# from http.client import responses
#
# import allure
# import pytest
# import requests
#
# sess = requests.session()
# from common.yaml_tools import YamlTools
#
# api_login_data = YamlTools.read_yaml_file("api\\api_login.yaml")[0]
# @allure.epic(api_login_data[""])
# @pytest.mark.parametrize("logindata",api_login_data["parametrize"])
# def test_login_001(logindata):
#     # log.info(f"执行登录接口的测试用例{abc.get('用例标题')}")
#     url = "http://192.168.1.37:8080"+api_login_data["request"]["url"]
#     data = logindata["data"]
#     response = sess.request(api_login_data["request"]["method"],url,data=data)
#     print(response.json())
#     # assert_text = response.j
#     # driver.find_element(By.ID,"account").send_keys(abc["username"])
#     # driver.find_element(By.ID,"password").send_keys(abc["password"])
#     # driver.find_element(By.ID,"submit").click()
#     # sleep(3)
#     # log.info(abc["expect"])
#     # if abc["expect"]=="s-menu-superadmin":
#     #     assert_text = driver.find_element(By.ID,"s-menu-superadmin").get_attribute("data-order")
#     #     assert assert_text == '7',"异常文本，查询失败"
#     #     log.info(f"assert_text={assert_text}")
#     #
#     # else:
#     #     sleep(3)
#     #
#     #     assert_text = driver.find_element(By.XPATH,'/html/body/div[2]/div/div/div[1]/div').text
#     #     assert assert_text == abc["expect"],"异常文本。查询失败"
from http.client import responses

import allure
import pytest
import requests
version = '1.0'
sess = requests.session()
from common.yaml_tools import YamlTools
from common.api.Base_request import BaseRequest

api_login_data = YamlTools.read_yaml_file("api\\api_login.yaml")[0]
api_query_data = YamlTools.read_yaml_file("api\\api_query.yaml")[0]
api_getSku_data = YamlTools.read_yaml_file("api\\getSku.yaml")[0]
@allure.epic(api_login_data["request"]["epic"])
@allure.feature(api_login_data["request"]["feature"])
@allure.story(api_login_data["request"]["story"])
@allure.title("我是标题")
@pytest.mark.parametrize("logindata",api_login_data["parametrize"])
# def test_login_001(logindata):
#     url = "http://192.168.1.37:8080"+api_login_data["request"]["url"]
#     data = logindata["data"]
#     response = sess.request(api_login_data["request"]["method"],url,data=data)
#     assert_text = response.json()['message']
#     assert assert_text == logindata["expect"],'登录失败'
def test_login_001(logindata):
    allure.dynamic.title(logindata["title"])
    response = BaseRequest.excute_api_request(api_login_data["request"],logindata)
    print(response.json())
    assert_text = response.json().get("message")
    assert assert_text == logindata["expect"],"登录失败"
    # url = "http://192.168.1.37:8080"+api_login_data["request"]["url"]
    # data = logindata["data"]
    # response = sess.request(api_login_data["request"]["method"],url,data=data)
    # assert_text = response.json()['message']
    # assert assert_text == logindata["expect"],'登录失败'
@allure.epic(api_query_data["request"]["epic"])
@allure.feature(api_query_data["request"]["feature"])
@allure.story(api_query_data["request"]["story"])
# @pytest.mark.skipif(version=="2.0",reason="用例缺陷")

@pytest.mark.parametrize("logindata", api_login_data["parametrize"])
@pytest.mark.parametrize("querydata",api_query_data["parametrize"])
def test_query_001(logindata,querydata):
    url = "http://192.168.1.37:8080"+api_login_data["request"]["url"]
    data = logindata["data"]
    response = sess.request(api_login_data["request"]["method"], url, data=data)

    urlQuery = "http://192.168.1.37:8080"+api_query_data["request"]["url"]
    params = querydata["params"]
    responseQ = sess.request(api_query_data["request"]["method"],urlQuery,params=params)

    print(responseQ.json())
    assert_textQ = responseQ.json().get("message")
    assert assert_textQ == querydata["expect"],"登录失败"

@pytest.mark.parametrize("getSkudata", api_getSku_data["parametrize"])
def test_getSku(getSkudata):
    urlSku = "http://192.168.1.37:8080" + api_getSku_data["request"]["url"]
    params = getSkudata["params"]
    responseQ = sess.request(api_getSku_data["request"]["method"], urlSku, params=params)

    print(responseQ.json())
    assert_textQ = responseQ.json().get("message")
    assert assert_textQ == getSkudata["expect"], "登录失败"